package ATM.frame;

import ATM.pojo.UserDO;

import javax.swing.*;
import java.awt.*;
import java.util.ArrayList;

public class ATMmain extends JFrame {
    private ArrayList<UserDO> users ;
    private Image bgImage = util.Util.getImage("/images/background.jpg");
    private CardLayout cardLayout = new CardLayout();
    private LoginPanel loginPanel = new LoginPanel(this);
    private MenuPanel menuPanel = new MenuPanel(this);
    private QueryPanel queryPanel = new QueryPanel(this);
    private  TransferPanel transferPanel= new TransferPanel(this);

    private DepositPanel depositPanel = new DepositPanel(this);
    private WithdrawPanel withdrawPanel = new WithdrawPanel(this);
    private ModifyPanel modifyPanel = new ModifyPanel(this);



    private UserDO loginUser;



    //无参构造函数  设置窗口及属性
    public ATMmain() {
        this.setContentPane(new JPanel() {
            @Override
            protected void paintComponent(Graphics g) {
                super.paintComponent(g);
                g.drawImage(bgImage, 0, 0, 1024, 768, this);
            }
        });

        this.setLayout(cardLayout);
        this.add("loginPanel",loginPanel);
        this.add("menuPanel",menuPanel);
        this.add("depositPanel",depositPanel);
        this.add("withDrawPanel",withdrawPanel);
        this.add("queryPanel",queryPanel);
        this.add("modifyPanel",modifyPanel);
        this.add("transferPanel",transferPanel);

        this.setSize(1024, 768);
        this.setTitle("中国银行客户端");
        this.setLocationRelativeTo(null);
        this.setDefaultCloseOperation(EXIT_ON_CLOSE);
        this.setVisible(true);
    }

    //得到所有子页面的情况
    public DepositPanel getDepositPanel() {
        return depositPanel;
    }

    public LoginPanel getLoginPanel() {
        return loginPanel;
    }

    public MenuPanel getMenuPanel() {
        return menuPanel;
    }

    public QueryPanel getQueryPanel() {
        return queryPanel;
    }

    public WithdrawPanel getWithdrawPanel() {
        return withdrawPanel;
    }

    public ModifyPanel getModifyPanel() {
        return modifyPanel;
    }

    public TransferPanel getTransferPanel() {
        return transferPanel;
    }

    //获取登录的人set、get函数
    public UserDO getLoginUser() {
        return loginUser;
    }

    public void setLoginUser(UserDO loginUser) {
        this.loginUser = loginUser;
    }



    //获取集合的set、get函数
    public ArrayList<UserDO> getUserList() {
        return users;
    }

    public void setUsers(ArrayList<UserDO> users) {
        this.users = users;
    }



    //方法

    //初始化用户信息集合
   /* public void init(){

        Connection con=util.CreateConnection.getConnection();
        Statement statement = null;
        ResultSet rs = null;
        try {
            statement=con.createStatement();
            String sql = "select u_usename name,u_usepsw psw,u_money money,u_id id from t_user";
            rs=statement.executeQuery(sql);
            while (rs.next()){
                UserDO users = new UserDO();
                users.setUserName(rs.getString("name"));
                users.setUserPassWord(rs.getString("psw"));
                users.setMoney(rs.getInt("money"));
                users.setId(rs.getInt("id"));
                userList.add(users);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }finally {
            util.CloseFunction.close(con,statement,rs);
        }*/


      /*  userList.add(new UserDO("wanger","123123",6000));
        userList.add(new UserDO("zhangsan","456456",5000));
        userList.add(new UserDO("lisi","444444",5500));
        userList.add(new UserDO("xiaowu","555555",10000));
        userList.add(new UserDO("zhaoliu","666666",12000));*/
        //转文件
//    util.FileChange.ObjectToBinary("111.dat",this.userList);
        //转对象
        //  this.userList =(ArrayList) util.FileChange.BinaryToObject("111.dat");


//        System.out.println(aaaa);
//        System.out.println(this.userList);



    //在有main函数的类里面写，不然每次都要被初始化
    public void balance(){


        this.getQueryPanel().getjLabel2().setText(this.getLoginUser().getMoney()+"");



        //this.getQueryPanel().getjLabel2().setText();

//        getQueryPanel().getjLabel2().setText(getLoginUser().getMoney()+"");
    }

    public void switchPanel(String name){
        cardLayout.show(this.getContentPane(),name);
    }

    public static void main(String[] args) {

        ATMmain aaaa=   new ATMmain();
        System.out.println(aaaa.users);

    }
}
